<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Goods_size_model short summary.
 *
 * Goods_size_model description.
 *
 * @version 1.0
 * @author GALAXY
 */
class Goods_size_model extends CI_Model
{
    public $goods_size_id;
    public $goods_id;
    public $size_id;
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function get_all_size_by_goods_size($goodsid)
    {
        $sql="SELECT g.goods_id,g.goods_size_id,g.size_id,s.title FROM goods_size g  LEFT JOIN size s on s.size_id=g.size_id where goods_id=$goodsid";
        return $this->db->query($sql)->result_array();
    }

    public function insert_goods_size($goodssizeModel)
    {
        return $this->db->insert('goods_size',$goodssizeModel);
    }

    public function del_goods_size($goodssizeModel)
    {
        $this->db->trans_begin();
        $this->db->delete('goods_size',array('goods_id'=>$goodssizeModel->goods_id,'size_id'=>$goodssizeModel->size_id));
        $this->db->delete('goods_inventory',array('goods_id'=>$goodssizeModel->goods_id,'goods_size_id'=>$goodssizeModel->size_id));
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            return 0;
        }
        else
        {
            $this->db->trans_commit();
            return 1;
        }
    }
}